﻿using System;
using System.Linq;

namespace EstateNuke.Data
{
    public partial class LeaseAgreementState
    {
        #region Fileds & Properties

        /// <summary>
        /// </summary>
        public string DisplayName
        {
            get
            {
                return string.Format("{0}{1}", Name, IsDeleted ? " (已删除)" : "");
            }
        }

        #endregion

        #region Delete

        ///// <summary>
        ///// </summary>
        //public void Delete(User modifiedUser)
        //{
        //    if (modifiedUser == null)
        //    {
        //        throw new ArgumentNullException("modifiedUser");
        //    }
        //    IsDeleted = true;
        //    ModifiedDate = DateTime.Now;
        //    ModifiedByUser = modifiedUser;
        //}

        ///// <summary>
        ///// </summary>
        //public void CancelDelete(User modifiedUser)
        //{
        //    if (modifiedUser == null)
        //    {
        //        throw new ArgumentNullException("modifiedUser");
        //    }
        //    IsDeleted = false;
        //    ModifiedDate = DateTime.Now;
        //    ModifiedByUser = modifiedUser;
        //}

        #endregion
    }

    public class LeaseAgreementStateEnum
    {
        #region Fields & Properties

        private readonly EstateNukeCore _context;

        private LeaseAgreementState _none;

        /// <summary>
        /// </summary>
        public LeaseAgreementState None
        {
            get
            {
                return _none ?? (_none = _context.LeaseAgreementStates.FirstOrDefault(leaseAgreementState => leaseAgreementState.Id == 0));
            }
        }

        private LeaseAgreementState _ordered;

        /// <summary>
        /// </summary>
        public LeaseAgreementState Ordered
        {
            get
            {
                return _ordered ?? (_ordered = _context.LeaseAgreementStates.FirstOrDefault(leaseAgreementState => leaseAgreementState.Id == 1));
            }
        }

        private LeaseAgreementState _contracted;

        /// <summary>
        /// </summary>
        public LeaseAgreementState Contracted
        {
            get
            {
                return _contracted ?? (_contracted = _context.LeaseAgreementStates.FirstOrDefault(leaseAgreementState => leaseAgreementState.Id == 2));
            }
        }

        private LeaseAgreementState _cancelled;

        /// <summary>
        /// </summary>
        public LeaseAgreementState Cancelled
        {
            get
            {
                return _cancelled ?? (_cancelled = _context.LeaseAgreementStates.FirstOrDefault(leaseAgreementState => leaseAgreementState.Id == 4));
            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// </summary>
        /// <param name = "context"></param>
        public LeaseAgreementStateEnum(EstateNukeCore context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            _context = context;
        }

        #endregion
    }
}